source("../../lib/som-utils.R")
Attaching package: 'dplyr'
The following objects are masked from 'package:stats':
filter, lag
The following objects are masked from 'package:base':
intersect, setdiff, setequal, union
source("../../lib/maps-utils.R")
Linking to GEOS 3.8.0, GDAL 3.0.4, PROJ 6.3.1
mpr.set_base_path_analysis()
model <- mpr.load_model("som-369.rds.xz")
summary(model)
SOM of size 5x5 with a hexagonal topology and a bubble neighbourhood function.
The number of data layers is 1.
Distance measure(s) used: sumofsquares.
Training data included: 94881 objects.
Mean distance to the closest unit in the map: 0.05.
plot(model, type="changes")
df <- mpr.load_data("datos_mes.csv.xz")
df
summary(df)
id_estacion fecha fecha_cnt tmax
Length:94881 Length:94881 Min. : 1.000 Min. :-53.0
Class :character Class :character 1st Qu.: 4.000 1st Qu.:148.0
Mode :character Mode :character Median : 6.000 Median :198.0
Mean : 6.497 Mean :200.2
3rd Qu.: 9.000 3rd Qu.:255.0
Max. :12.000 Max. :403.0
tmin precip nevada prof_nieve
Min. :-121.00 Min. : 0.00 Min. :0.000000 Min. : 0.000
1st Qu.: 53.00 1st Qu.: 3.00 1st Qu.:0.000000 1st Qu.: 0.000
Median : 98.00 Median : 10.00 Median :0.000000 Median : 0.000
Mean : 98.86 Mean : 16.25 Mean :0.000295 Mean : 0.467
3rd Qu.: 148.00 3rd Qu.: 22.00 3rd Qu.:0.000000 3rd Qu.: 0.000
Max. : 254.00 Max. :422.00 Max. :6.000000 Max. :1834.000
longitud latitud altitud
Min. :27.82 Min. :-17.8889 Min. : 1.0
1st Qu.:38.28 1st Qu.: -5.6417 1st Qu.: 42.0
Median :40.82 Median : -3.4500 Median : 247.0
Mean :39.66 Mean : -3.4350 Mean : 418.5
3rd Qu.:42.08 3rd Qu.: 0.4914 3rd Qu.: 656.0
Max. :43.57 Max. : 4.2156 Max. :2535.0
world <- ne_countries(scale = "medium", returnclass = "sf")
spain <- subset(world, admin == "Spain")
plot(model, type="count", shape = "straight", palette.name = mpr.degrade.bleu)
NĂºmero de elementos en cada celda:
nb <- table(model$unit.classif)
print(nb)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
4183 5167 5420 2176 757 4626 4572 6068 4164 1948 3821 4133 5048 4378 3228 3091
17 18 19 20 21 22 23 24 25
2975 3594 4850 5465 2715 3114 3384 2893 3111
ComprobaciĂ³n de nodos vacĂos:
dim_model <- 5*5;
len_nb = length(nb);
empty_nodes <- dim_model != len_nb;
if (empty_nodes) {
print(paste("[Warning] Existen nodos vacĂos: ", len_nb, "/", dim_model))
}
plot(model, type="dist.neighbours", shape = "straight")
model_colnames = c("tmax", "tmin")
model_ncol = length(model_colnames)
plot(model, shape = "straight")
par(mfrow=c(3,4))
for (j in 1:model_ncol) {
plot(model, type="property", property=getCodes(model,1)[,j],
palette.name=mpr.coolBlueHotRed,
main=model_colnames[j],
cex=0.5, shape = "straight")
}
if (!empty_nodes) {
cor <- apply(getCodes(model,1), 2, mpr.weighted.correlation, w=nb, som=model)
print(cor)
}
tmax tmin
[1,] -0.5150303 -0.7848423
[2,] 0.7210027 0.4158785
RepresentaciĂ³n de cada variable en un mapa de factores:
if (!empty_nodes) {
par(mfrow=c(1,1))
plot(cor[1,], cor[2,], xlim=c(-1,1), ylim=c(-1,1), type="n")
lines(c(-1,1),c(0,0))
lines(c(0,0),c(-1,1))
text(cor[1,], cor[2,], labels=model_colnames, cex=0.75)
symbols(0,0,circles=1,inches=F,add=T)
}
Importancia de cada variable - varianza ponderada por el tamaño de la celda:
if (!empty_nodes) {
sigma2 <- sqrt(apply(getCodes(model,1),2,function(x,effectif)
{m<-sum(effectif*(x-weighted.mean(x,effectif))^2)/(sum(effectif)-1)},
effectif=nb))
print(sort(sigma2,decreasing=T))
}
tmin tmax
0.9875701 0.9874356
if (!empty_nodes) {
hac <- mpr.hac(model, nb)
}
if (!empty_nodes) {
plot(hac, hang=-1, labels=F)
rect.hclust(hac, k=3)
}
A quĂ© clĂºster pertenece cada nodo del mapa de kohonen:
if (!empty_nodes) {
groups <- cutree(hac, k=3)
plot(model, type="mapping",
bgcol=c("steelblue1","sienna1","yellowgreen","red","blue","yellow","purple","green","white","#1f77b4", '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#8c564b', '#e377c2')[groups],
shape = "straight", labels = "")
add.cluster.boundaries(model, clustering=groups)
}
if (!empty_nodes) {
# Asignamos a cada registro su clĂºster
df$cluster <- groups[model$unit.classif]
}
Nuevos dataframes por cluster
if (!empty_nodes) {
# Creo nuevos dataframes, uno por cada clĂºster.
df.cluster01 <- subset(df, cluster==1)
df.cluster02 <- subset(df, cluster==2)
df.cluster03 <- subset(df, cluster==3)
# Extraigo del dataframe las features.
df.cluster01 <- select(df.cluster01, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster02 <- select(df.cluster02, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster03 <- select(df.cluster03, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
}
if (!empty_nodes) summary(df.cluster01)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. : 87.0 Min. :-31.00 Min. : 0.00 Min. :0
1st Qu.: 3.000 1st Qu.:156.0 1st Qu.: 60.00 1st Qu.: 6.00 1st Qu.:0
Median : 5.000 Median :175.0 Median : 78.00 Median : 15.00 Median :0
Mean : 6.072 Mean :176.9 Mean : 77.81 Mean : 20.89 Mean :0
3rd Qu.:10.000 3rd Qu.:197.0 3rd Qu.: 97.00 3rd Qu.: 28.00 3rd Qu.:0
Max. :12.000 Max. :265.0 Max. :157.00 Max. :371.00 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.00000 Min. :27.82 Min. :-17.8889 Min. : 1
1st Qu.: 0.00000 1st Qu.:38.37 1st Qu.: -5.6156 1st Qu.: 42
Median : 0.00000 Median :40.95 Median : -2.9056 Median : 143
Mean : 0.04087 Mean :40.25 Mean : -2.9106 Mean : 359
3rd Qu.: 0.00000 3rd Qu.:42.33 3rd Qu.: 0.4914 3rd Qu.: 609
Max. :59.00000 Max. :43.57 Max. : 4.2156 Max. :2535
if (!empty_nodes) summary(df.cluster02)
fecha_cnt tmax tmin precip
Min. : 1.000 Min. :-53.0 Min. :-121.00 Min. : 0.00
1st Qu.: 1.000 1st Qu.: 86.0 1st Qu.: -3.00 1st Qu.: 6.00
Median : 3.000 Median :106.0 Median : 15.00 Median : 13.00
Mean : 5.542 Mean :100.7 Mean : 12.16 Mean : 20.25
3rd Qu.:11.000 3rd Qu.:122.0 3rd Qu.: 32.00 3rd Qu.: 27.00
Max. :12.000 Max. :199.0 Max. : 76.00 Max. :309.00
nevada prof_nieve longitud latitud
Min. :0.000000 Min. : 0.00 Min. :28.31 Min. :-16.4992
1st Qu.:0.000000 1st Qu.: 0.00 1st Qu.:40.66 1st Qu.: -4.5353
Median :0.000000 Median : 0.00 Median :41.62 Median : -2.7331
Mean :0.001583 Mean : 2.41 Mean :41.00 Mean : -2.8208
3rd Qu.:0.000000 3rd Qu.: 0.00 3rd Qu.:42.38 3rd Qu.: 0.4483
Max. :6.000000 Max. :1834.00 Max. :43.57 Max. : 4.2156
altitud
Min. : 1.0
1st Qu.: 459.0
Median : 704.0
Mean : 862.9
3rd Qu.:1004.0
Max. :2535.0
if (!empty_nodes) summary(df.cluster03)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. :173.0 Min. : 57 Min. : 0.000 Min. :0
1st Qu.: 6.000 1st Qu.:240.0 1st Qu.:136 1st Qu.: 1.000 1st Qu.:0
Median : 7.000 Median :267.0 Median :157 Median : 5.000 Median :0
Mean : 7.348 Mean :268.4 Mean :159 Mean : 9.873 Mean :0
3rd Qu.: 9.000 3rd Qu.:296.0 3rd Qu.:182 3rd Qu.: 14.000 3rd Qu.:0
Max. :12.000 Max. :403.0 Max. :254 Max. :422.000 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.0000 Min. :27.82 Min. :-17.8889 Min. : 1.0
1st Qu.: 0.0000 1st Qu.:37.18 1st Qu.: -6.0556 1st Qu.: 27.1
Median : 0.0000 Median :39.88 Median : -3.6781 Median : 85.0
Mean : 0.0027 Mean :38.48 Mean : -4.2300 Mean : 275.1
3rd Qu.: 0.0000 3rd Qu.:41.63 3rd Qu.: 0.3994 3rd Qu.: 534.0
Max. :35.0000 Max. :43.57 Max. : 4.2156 Max. :2371.0
if (!empty_nodes) {
df.clusters.dim <- c(dim(df.cluster01)[1], dim(df.cluster02)[1], dim(df.cluster03)[1])
barplot(df.clusters.dim,
names.arg = c("cluster01", "cluster02", "cluster03"),
col = "steelblue1")
}
if (!empty_nodes) mpr.hist(df.cluster01)
if (!empty_nodes) mpr.hist(df.cluster02)
if (!empty_nodes) mpr.hist(df.cluster03)
if (!empty_nodes) mpr.boxplot(df.cluster01)
if (!empty_nodes) mpr.boxplot(df.cluster02)
if (!empty_nodes) mpr.boxplot(df.cluster03)
# Agrupa por longitud y latitud para rellenar el mapa con menos datos.
if (!empty_nodes) {
df.cluster01.grouped <- mpr.group_by_geo(df.cluster01)
df.cluster02.grouped <- mpr.group_by_geo(df.cluster02)
df.cluster03.grouped <- mpr.group_by_geo(df.cluster03)
}
if (!empty_nodes) mpr.draw_map(spain, df.cluster01.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster02.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster03.grouped)
if (!empty_nodes) {
plot(hac, hang=-1, labels=F)
rect.hclust(hac, k=4)
}
A quĂ© clĂºster pertenece cada nodo del mapa de kohonen:
if (!empty_nodes) {
groups <- cutree(hac, k=4)
plot(model, type="mapping",
bgcol=c("steelblue1","sienna1","yellowgreen","red","blue","yellow","purple","green","white","#1f77b4", '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#8c564b', '#e377c2')[groups],
shape = "straight", labels = "")
add.cluster.boundaries(model, clustering=groups)
}
if (!empty_nodes) {
# Asignamos a cada registro su clĂºster
df$cluster <- groups[model$unit.classif]
}
Nuevos dataframes por cluster
if (!empty_nodes) {
# Creo nuevos dataframes, uno por cada clĂºster.
df.cluster01 <- subset(df, cluster==1)
df.cluster02 <- subset(df, cluster==2)
df.cluster03 <- subset(df, cluster==3)
df.cluster04 <- subset(df, cluster==4)
# Extraigo del dataframe las features.
df.cluster01 <- select(df.cluster01, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster02 <- select(df.cluster02, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster03 <- select(df.cluster03, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster04 <- select(df.cluster04, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
}
if (!empty_nodes) summary(df.cluster01)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. : 87.0 Min. :-31.00 Min. : 0.00 Min. :0
1st Qu.: 3.000 1st Qu.:156.0 1st Qu.: 60.00 1st Qu.: 6.00 1st Qu.:0
Median : 5.000 Median :175.0 Median : 78.00 Median : 15.00 Median :0
Mean : 6.072 Mean :176.9 Mean : 77.81 Mean : 20.89 Mean :0
3rd Qu.:10.000 3rd Qu.:197.0 3rd Qu.: 97.00 3rd Qu.: 28.00 3rd Qu.:0
Max. :12.000 Max. :265.0 Max. :157.00 Max. :371.00 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.00000 Min. :27.82 Min. :-17.8889 Min. : 1
1st Qu.: 0.00000 1st Qu.:38.37 1st Qu.: -5.6156 1st Qu.: 42
Median : 0.00000 Median :40.95 Median : -2.9056 Median : 143
Mean : 0.04087 Mean :40.25 Mean : -2.9106 Mean : 359
3rd Qu.: 0.00000 3rd Qu.:42.33 3rd Qu.: 0.4914 3rd Qu.: 609
Max. :59.00000 Max. :43.57 Max. : 4.2156 Max. :2535
if (!empty_nodes) summary(df.cluster02)
fecha_cnt tmax tmin precip
Min. : 1.000 Min. :-53.0 Min. :-121.00 Min. : 0.00
1st Qu.: 1.000 1st Qu.: 86.0 1st Qu.: -3.00 1st Qu.: 6.00
Median : 3.000 Median :106.0 Median : 15.00 Median : 13.00
Mean : 5.542 Mean :100.7 Mean : 12.16 Mean : 20.25
3rd Qu.:11.000 3rd Qu.:122.0 3rd Qu.: 32.00 3rd Qu.: 27.00
Max. :12.000 Max. :199.0 Max. : 76.00 Max. :309.00
nevada prof_nieve longitud latitud
Min. :0.000000 Min. : 0.00 Min. :28.31 Min. :-16.4992
1st Qu.:0.000000 1st Qu.: 0.00 1st Qu.:40.66 1st Qu.: -4.5353
Median :0.000000 Median : 0.00 Median :41.62 Median : -2.7331
Mean :0.001583 Mean : 2.41 Mean :41.00 Mean : -2.8208
3rd Qu.:0.000000 3rd Qu.: 0.00 3rd Qu.:42.38 3rd Qu.: 0.4483
Max. :6.000000 Max. :1834.00 Max. :43.57 Max. : 4.2156
altitud
Min. : 1.0
1st Qu.: 459.0
Median : 704.0
Mean : 862.9
3rd Qu.:1004.0
Max. :2535.0
if (!empty_nodes) summary(df.cluster03)
fecha_cnt tmax tmin precip nevada
Min. : 1.00 Min. :173.0 Min. : 57 Min. : 0.00 Min. :0
1st Qu.: 6.00 1st Qu.:226.0 1st Qu.:127 1st Qu.: 3.00 1st Qu.:0
Median : 7.00 Median :246.0 Median :141 Median : 9.00 Median :0
Mean : 7.18 Mean :246.3 Mean :140 Mean : 13.15 Mean :0
3rd Qu.: 9.00 3rd Qu.:267.0 3rd Qu.:156 3rd Qu.: 18.00 3rd Qu.:0
Max. :12.00 Max. :336.0 Max. :195 Max. :422.00 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.00000 Min. :27.82 Min. :-17.8889 Min. : 1
1st Qu.: 0.00000 1st Qu.:37.26 1st Qu.: -6.2567 1st Qu.: 32
Median : 0.00000 Median :40.82 Median : -3.7892 Median : 98
Mean : 0.00444 Mean :38.93 Mean : -4.5345 Mean : 318
3rd Qu.: 0.00000 3rd Qu.:42.18 3rd Qu.: 0.0406 3rd Qu.: 609
Max. :35.00000 Max. :43.57 Max. : 4.2156 Max. :2371
if (!empty_nodes) summary(df.cluster04)
fecha_cnt tmax tmin precip nevada
Min. : 2.000 Min. :226.0 Min. :111 Min. : 0.000 Min. :0
1st Qu.: 7.000 1st Qu.:280.0 1st Qu.:173 1st Qu.: 0.000 1st Qu.:0
Median : 8.000 Median :301.0 Median :188 Median : 1.000 Median :0
Mean : 7.597 Mean :300.9 Mean :187 Mean : 5.038 Mean :0
3rd Qu.: 8.000 3rd Qu.:321.0 3rd Qu.:203 3rd Qu.: 6.000 3rd Qu.:0
Max. :12.000 Max. :403.0 Max. :254 Max. :320.000 Max. :0
prof_nieve longitud latitud altitud
Min. :0.0000000 Min. :27.82 Min. :-17.8889 Min. : 1.0
1st Qu.:0.0000000 1st Qu.:36.85 1st Qu.: -5.8792 1st Qu.: 25.0
Median :0.0000000 Median :38.88 Median : -2.9553 Median : 68.6
Mean :0.0001273 Mean :37.82 Mean : -3.7804 Mean : 211.6
3rd Qu.:0.0000000 3rd Qu.:40.82 3rd Qu.: 0.4942 3rd Qu.: 412.0
Max. :2.0000000 Max. :43.56 Max. : 4.2156 Max. :1167.0
if (!empty_nodes) {
df.clusters.dim <- c(dim(df.cluster01)[1], dim(df.cluster02)[1], dim(df.cluster03)[1], dim(df.cluster04)[1])
barplot(df.clusters.dim,
names.arg = c("cluster01", "cluster02", "cluster03", "cluster04"),
col = "steelblue1")
}
if (!empty_nodes) mpr.hist(df.cluster01)
if (!empty_nodes) mpr.hist(df.cluster02)
if (!empty_nodes) mpr.hist(df.cluster03)
if (!empty_nodes) mpr.hist(df.cluster04)
if (!empty_nodes) mpr.boxplot(df.cluster01)
if (!empty_nodes) mpr.boxplot(df.cluster02)
if (!empty_nodes) mpr.boxplot(df.cluster03)
if (!empty_nodes) mpr.boxplot(df.cluster04)
# Agrupa por longitud y latitud para rellenar el mapa con menos datos.
if (!empty_nodes) {
df.cluster01.grouped <- mpr.group_by_geo(df.cluster01)
df.cluster02.grouped <- mpr.group_by_geo(df.cluster02)
df.cluster03.grouped <- mpr.group_by_geo(df.cluster03)
df.cluster04.grouped <- mpr.group_by_geo(df.cluster04)
}
if (!empty_nodes) mpr.draw_map(spain, df.cluster01.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster02.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster03.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster04.grouped)
if (!empty_nodes) {
plot(hac, hang=-1, labels=F)
rect.hclust(hac, k=5)
}
A quĂ© clĂºster pertenece cada nodo del mapa de kohonen:
if (!empty_nodes) {
groups <- cutree(hac, k=5)
plot(model, type="mapping",
bgcol=c("steelblue1","sienna1","yellowgreen","red","blue","yellow","purple","green","white","#1f77b4", '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#8c564b', '#e377c2')[groups],
shape = "straight", labels = "")
add.cluster.boundaries(model, clustering=groups)
}
if (!empty_nodes) {
# Asignamos a cada registro su clĂºster
df$cluster <- groups[model$unit.classif]
}
Nuevos dataframes por cluster
if (!empty_nodes) {
# Creo nuevos dataframes, uno por cada clĂºster.
df.cluster01 <- subset(df, cluster==1)
df.cluster02 <- subset(df, cluster==2)
df.cluster03 <- subset(df, cluster==3)
df.cluster04 <- subset(df, cluster==4)
df.cluster05 <- subset(df, cluster==5)
# Extraigo del dataframe las features.
df.cluster01 <- select(df.cluster01, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster02 <- select(df.cluster02, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster03 <- select(df.cluster03, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster04 <- select(df.cluster04, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster05 <- select(df.cluster05, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
}
if (!empty_nodes) summary(df.cluster01)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. : 87.0 Min. :-31.00 Min. : 0.00 Min. :0
1st Qu.: 3.000 1st Qu.:156.0 1st Qu.: 60.00 1st Qu.: 6.00 1st Qu.:0
Median : 5.000 Median :175.0 Median : 78.00 Median : 15.00 Median :0
Mean : 6.072 Mean :176.9 Mean : 77.81 Mean : 20.89 Mean :0
3rd Qu.:10.000 3rd Qu.:197.0 3rd Qu.: 97.00 3rd Qu.: 28.00 3rd Qu.:0
Max. :12.000 Max. :265.0 Max. :157.00 Max. :371.00 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.00000 Min. :27.82 Min. :-17.8889 Min. : 1
1st Qu.: 0.00000 1st Qu.:38.37 1st Qu.: -5.6156 1st Qu.: 42
Median : 0.00000 Median :40.95 Median : -2.9056 Median : 143
Mean : 0.04087 Mean :40.25 Mean : -2.9106 Mean : 359
3rd Qu.: 0.00000 3rd Qu.:42.33 3rd Qu.: 0.4914 3rd Qu.: 609
Max. :59.00000 Max. :43.57 Max. : 4.2156 Max. :2535
if (!empty_nodes) summary(df.cluster02)
fecha_cnt tmax tmin precip
Min. : 1.000 Min. : 20.0 Min. :-80.00 Min. : 0.00
1st Qu.: 1.000 1st Qu.: 89.0 1st Qu.: -1.00 1st Qu.: 5.00
Median : 3.000 Median :108.0 Median : 17.00 Median : 13.00
Mean : 5.575 Mean :104.8 Mean : 15.14 Mean : 19.43
3rd Qu.:11.000 3rd Qu.:123.0 3rd Qu.: 33.00 3rd Qu.: 26.00
Max. :12.000 Max. :199.0 Max. : 76.00 Max. :309.00
nevada prof_nieve longitud latitud
Min. :0.000000 Min. : 0.000 Min. :28.31 Min. :-16.4992
1st Qu.:0.000000 1st Qu.: 0.000 1st Qu.:40.66 1st Qu.: -4.6800
Median :0.000000 Median : 0.000 Median :41.59 Median : -3.1642
Mean :0.001653 Mean : 1.347 Mean :40.95 Mean : -2.9478
3rd Qu.:0.000000 3rd Qu.: 0.000 3rd Qu.:42.36 3rd Qu.: 0.3056
Max. :6.000000 Max. :1494.000 Max. :43.57 Max. : 4.2156
altitud
Min. : 1.0
1st Qu.: 445.0
Median : 687.0
Mean : 804.8
3rd Qu.: 945.0
Max. :2535.0
if (!empty_nodes) summary(df.cluster03)
fecha_cnt tmax tmin precip
Min. : 1.000 Min. :-53.000 Min. :-121.00 Min. : 0.00
1st Qu.: 2.000 1st Qu.: -4.000 1st Qu.: -65.00 1st Qu.: 17.00
Median : 3.000 Median : 11.000 Median : -51.00 Median : 33.00
Mean : 4.798 Mean : 8.683 Mean : -54.46 Mean : 38.67
3rd Qu.:11.000 3rd Qu.: 23.000 3rd Qu.: -41.00 3rd Qu.: 54.00
Max. :12.000 Max. : 75.000 Max. : -20.00 Max. :180.00
nevada prof_nieve longitud latitud
Min. :0 Min. : 0.00 Min. :28.31 Min. :-16.49920
1st Qu.:0 1st Qu.: 0.00 1st Qu.:42.18 1st Qu.: 0.73170
Median :0 Median : 0.00 Median :42.47 Median : 0.98440
Mean :0 Mean : 26.19 Mean :42.12 Mean : 0.01983
3rd Qu.:0 3rd Qu.: 0.00 3rd Qu.:42.64 3rd Qu.: 1.36560
Max. :0 Max. :1834.00 Max. :42.85 Max. : 2.43780
altitud
Min. : 162
1st Qu.:1894
Median :2247
Mean :2165
3rd Qu.:2400
Max. :2535
if (!empty_nodes) summary(df.cluster04)
fecha_cnt tmax tmin precip nevada
Min. : 1.00 Min. :173.0 Min. : 57 Min. : 0.00 Min. :0
1st Qu.: 6.00 1st Qu.:226.0 1st Qu.:127 1st Qu.: 3.00 1st Qu.:0
Median : 7.00 Median :246.0 Median :141 Median : 9.00 Median :0
Mean : 7.18 Mean :246.3 Mean :140 Mean : 13.15 Mean :0
3rd Qu.: 9.00 3rd Qu.:267.0 3rd Qu.:156 3rd Qu.: 18.00 3rd Qu.:0
Max. :12.00 Max. :336.0 Max. :195 Max. :422.00 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.00000 Min. :27.82 Min. :-17.8889 Min. : 1
1st Qu.: 0.00000 1st Qu.:37.26 1st Qu.: -6.2567 1st Qu.: 32
Median : 0.00000 Median :40.82 Median : -3.7892 Median : 98
Mean : 0.00444 Mean :38.93 Mean : -4.5345 Mean : 318
3rd Qu.: 0.00000 3rd Qu.:42.18 3rd Qu.: 0.0406 3rd Qu.: 609
Max. :35.00000 Max. :43.57 Max. : 4.2156 Max. :2371
if (!empty_nodes) summary(df.cluster05)
fecha_cnt tmax tmin precip nevada
Min. : 2.000 Min. :226.0 Min. :111 Min. : 0.000 Min. :0
1st Qu.: 7.000 1st Qu.:280.0 1st Qu.:173 1st Qu.: 0.000 1st Qu.:0
Median : 8.000 Median :301.0 Median :188 Median : 1.000 Median :0
Mean : 7.597 Mean :300.9 Mean :187 Mean : 5.038 Mean :0
3rd Qu.: 8.000 3rd Qu.:321.0 3rd Qu.:203 3rd Qu.: 6.000 3rd Qu.:0
Max. :12.000 Max. :403.0 Max. :254 Max. :320.000 Max. :0
prof_nieve longitud latitud altitud
Min. :0.0000000 Min. :27.82 Min. :-17.8889 Min. : 1.0
1st Qu.:0.0000000 1st Qu.:36.85 1st Qu.: -5.8792 1st Qu.: 25.0
Median :0.0000000 Median :38.88 Median : -2.9553 Median : 68.6
Mean :0.0001273 Mean :37.82 Mean : -3.7804 Mean : 211.6
3rd Qu.:0.0000000 3rd Qu.:40.82 3rd Qu.: 0.4942 3rd Qu.: 412.0
Max. :2.0000000 Max. :43.56 Max. : 4.2156 Max. :1167.0
if (!empty_nodes) {
df.clusters.dim <- c(dim(df.cluster01)[1], dim(df.cluster02)[1], dim(df.cluster03)[1], dim(df.cluster04)[1], dim(df.cluster05)[1])
barplot(df.clusters.dim,
names.arg = c("cluster01", "cluster02", "cluster03", "cluster04", "cluster05"),
col = "steelblue1")
}
if (!empty_nodes) mpr.hist(df.cluster01)
if (!empty_nodes) mpr.hist(df.cluster02)
if (!empty_nodes) mpr.hist(df.cluster03)
if (!empty_nodes) mpr.hist(df.cluster04)
if (!empty_nodes) mpr.hist(df.cluster05)
if (!empty_nodes) mpr.boxplot(df.cluster01)
if (!empty_nodes) mpr.boxplot(df.cluster02)
if (!empty_nodes) mpr.boxplot(df.cluster03)
if (!empty_nodes) mpr.boxplot(df.cluster04)
if (!empty_nodes) mpr.boxplot(df.cluster05)
# Agrupa por longitud y latitud para rellenar el mapa con menos datos.
if (!empty_nodes) {
df.cluster01.grouped <- mpr.group_by_geo(df.cluster01)
df.cluster02.grouped <- mpr.group_by_geo(df.cluster02)
df.cluster03.grouped <- mpr.group_by_geo(df.cluster03)
df.cluster04.grouped <- mpr.group_by_geo(df.cluster04)
df.cluster05.grouped <- mpr.group_by_geo(df.cluster05)
}
if (!empty_nodes) mpr.draw_map(spain, df.cluster01.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster02.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster03.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster04.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster05.grouped)
if (!empty_nodes) {
plot(hac, hang=-1, labels=F)
rect.hclust(hac, k=6)
}
A quĂ© clĂºster pertenece cada nodo del mapa de kohonen:
if (!empty_nodes) {
groups <- cutree(hac, k=6)
plot(model, type="mapping",
bgcol=c("steelblue1","sienna1","yellowgreen","red","blue","yellow","purple","green","white","#1f77b4", '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#8c564b', '#e377c2')[groups],
shape = "straight", labels = "")
add.cluster.boundaries(model, clustering=groups)
}
if (!empty_nodes) {
# Asignamos a cada registro su clĂºster
df$cluster <- groups[model$unit.classif]
}
Nuevos dataframes por cluster
if (!empty_nodes) {
# Creo nuevos dataframes, uno por cada clĂºster.
df.cluster01 <- subset(df, cluster==1)
df.cluster02 <- subset(df, cluster==2)
df.cluster03 <- subset(df, cluster==3)
df.cluster04 <- subset(df, cluster==4)
df.cluster05 <- subset(df, cluster==5)
df.cluster06 <- subset(df, cluster==6)
# Extraigo del dataframe las features.
df.cluster01 <- select(df.cluster01, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster02 <- select(df.cluster02, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster03 <- select(df.cluster03, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster04 <- select(df.cluster04, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster05 <- select(df.cluster05, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster06 <- select(df.cluster06, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
}
if (!empty_nodes) summary(df.cluster01)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. : 87.0 Min. : 20.00 Min. : 0.00 Min. :0
1st Qu.: 4.000 1st Qu.:185.0 1st Qu.: 85.00 1st Qu.: 6.00 1st Qu.:0
Median : 5.000 Median :199.0 Median : 99.00 Median : 14.00 Median :0
Mean : 6.613 Mean :199.6 Mean : 97.74 Mean : 19.25 Mean :0
3rd Qu.:10.000 3rd Qu.:215.0 3rd Qu.:111.00 3rd Qu.: 26.00 3rd Qu.:0
Max. :12.000 Max. :265.0 Max. :157.00 Max. :279.00 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.00000 Min. :27.82 Min. :-17.8889 Min. : 1.0
1st Qu.: 0.00000 1st Qu.:37.96 1st Qu.: -5.6156 1st Qu.: 32.0
Median : 0.00000 Median :40.66 Median : -2.9553 Median : 98.0
Mean : 0.02868 Mean :39.80 Mean : -3.0701 Mean : 339.7
3rd Qu.: 0.00000 3rd Qu.:42.08 3rd Qu.: 0.4914 3rd Qu.: 570.8
Max. :38.00000 Max. :43.57 Max. : 4.2156 Max. :2519.0
if (!empty_nodes) summary(df.cluster02)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. :109.0 Min. :-31.00 Min. : 0.00 Min. :0
1st Qu.: 2.000 1st Qu.:146.0 1st Qu.: 49.00 1st Qu.: 6.00 1st Qu.:0
Median : 4.000 Median :158.0 Median : 62.00 Median : 16.00 Median :0
Mean : 5.631 Mean :158.3 Mean : 61.56 Mean : 22.21 Mean :0
3rd Qu.:11.000 3rd Qu.:170.0 3rd Qu.: 74.00 3rd Qu.: 30.00 3rd Qu.:0
Max. :12.000 Max. :250.0 Max. :115.00 Max. :371.00 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.00000 Min. :28.31 Min. :-16.4992 Min. : 1.0
1st Qu.: 0.00000 1st Qu.:39.47 1st Qu.: -5.6156 1st Qu.: 44.0
Median : 0.00000 Median :41.22 Median : -2.9056 Median : 185.0
Mean : 0.05081 Mean :40.61 Mean : -2.7805 Mean : 374.7
3rd Qu.: 0.00000 3rd Qu.:42.44 3rd Qu.: 0.5706 3rd Qu.: 611.0
Max. :59.00000 Max. :43.57 Max. : 4.2156 Max. :2535.0
if (!empty_nodes) summary(df.cluster03)
fecha_cnt tmax tmin precip
Min. : 1.000 Min. : 20.0 Min. :-80.00 Min. : 0.00
1st Qu.: 1.000 1st Qu.: 89.0 1st Qu.: -1.00 1st Qu.: 5.00
Median : 3.000 Median :108.0 Median : 17.00 Median : 13.00
Mean : 5.575 Mean :104.8 Mean : 15.14 Mean : 19.43
3rd Qu.:11.000 3rd Qu.:123.0 3rd Qu.: 33.00 3rd Qu.: 26.00
Max. :12.000 Max. :199.0 Max. : 76.00 Max. :309.00
nevada prof_nieve longitud latitud
Min. :0.000000 Min. : 0.000 Min. :28.31 Min. :-16.4992
1st Qu.:0.000000 1st Qu.: 0.000 1st Qu.:40.66 1st Qu.: -4.6800
Median :0.000000 Median : 0.000 Median :41.59 Median : -3.1642
Mean :0.001653 Mean : 1.347 Mean :40.95 Mean : -2.9478
3rd Qu.:0.000000 3rd Qu.: 0.000 3rd Qu.:42.36 3rd Qu.: 0.3056
Max. :6.000000 Max. :1494.000 Max. :43.57 Max. : 4.2156
altitud
Min. : 1.0
1st Qu.: 445.0
Median : 687.0
Mean : 804.8
3rd Qu.: 945.0
Max. :2535.0
if (!empty_nodes) summary(df.cluster04)
fecha_cnt tmax tmin precip
Min. : 1.000 Min. :-53.000 Min. :-121.00 Min. : 0.00
1st Qu.: 2.000 1st Qu.: -4.000 1st Qu.: -65.00 1st Qu.: 17.00
Median : 3.000 Median : 11.000 Median : -51.00 Median : 33.00
Mean : 4.798 Mean : 8.683 Mean : -54.46 Mean : 38.67
3rd Qu.:11.000 3rd Qu.: 23.000 3rd Qu.: -41.00 3rd Qu.: 54.00
Max. :12.000 Max. : 75.000 Max. : -20.00 Max. :180.00
nevada prof_nieve longitud latitud
Min. :0 Min. : 0.00 Min. :28.31 Min. :-16.49920
1st Qu.:0 1st Qu.: 0.00 1st Qu.:42.18 1st Qu.: 0.73170
Median :0 Median : 0.00 Median :42.47 Median : 0.98440
Mean :0 Mean : 26.19 Mean :42.12 Mean : 0.01983
3rd Qu.:0 3rd Qu.: 0.00 3rd Qu.:42.64 3rd Qu.: 1.36560
Max. :0 Max. :1834.00 Max. :42.85 Max. : 2.43780
altitud
Min. : 162
1st Qu.:1894
Median :2247
Mean :2165
3rd Qu.:2400
Max. :2535
if (!empty_nodes) summary(df.cluster05)
fecha_cnt tmax tmin precip nevada
Min. : 1.00 Min. :173.0 Min. : 57 Min. : 0.00 Min. :0
1st Qu.: 6.00 1st Qu.:226.0 1st Qu.:127 1st Qu.: 3.00 1st Qu.:0
Median : 7.00 Median :246.0 Median :141 Median : 9.00 Median :0
Mean : 7.18 Mean :246.3 Mean :140 Mean : 13.15 Mean :0
3rd Qu.: 9.00 3rd Qu.:267.0 3rd Qu.:156 3rd Qu.: 18.00 3rd Qu.:0
Max. :12.00 Max. :336.0 Max. :195 Max. :422.00 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.00000 Min. :27.82 Min. :-17.8889 Min. : 1
1st Qu.: 0.00000 1st Qu.:37.26 1st Qu.: -6.2567 1st Qu.: 32
Median : 0.00000 Median :40.82 Median : -3.7892 Median : 98
Mean : 0.00444 Mean :38.93 Mean : -4.5345 Mean : 318
3rd Qu.: 0.00000 3rd Qu.:42.18 3rd Qu.: 0.0406 3rd Qu.: 609
Max. :35.00000 Max. :43.57 Max. : 4.2156 Max. :2371
if (!empty_nodes) summary(df.cluster06)
fecha_cnt tmax tmin precip nevada
Min. : 2.000 Min. :226.0 Min. :111 Min. : 0.000 Min. :0
1st Qu.: 7.000 1st Qu.:280.0 1st Qu.:173 1st Qu.: 0.000 1st Qu.:0
Median : 8.000 Median :301.0 Median :188 Median : 1.000 Median :0
Mean : 7.597 Mean :300.9 Mean :187 Mean : 5.038 Mean :0
3rd Qu.: 8.000 3rd Qu.:321.0 3rd Qu.:203 3rd Qu.: 6.000 3rd Qu.:0
Max. :12.000 Max. :403.0 Max. :254 Max. :320.000 Max. :0
prof_nieve longitud latitud altitud
Min. :0.0000000 Min. :27.82 Min. :-17.8889 Min. : 1.0
1st Qu.:0.0000000 1st Qu.:36.85 1st Qu.: -5.8792 1st Qu.: 25.0
Median :0.0000000 Median :38.88 Median : -2.9553 Median : 68.6
Mean :0.0001273 Mean :37.82 Mean : -3.7804 Mean : 211.6
3rd Qu.:0.0000000 3rd Qu.:40.82 3rd Qu.: 0.4942 3rd Qu.: 412.0
Max. :2.0000000 Max. :43.56 Max. : 4.2156 Max. :1167.0
if (!empty_nodes) {
df.clusters.dim <- c(dim(df.cluster01)[1], dim(df.cluster02)[1], dim(df.cluster03)[1], dim(df.cluster04)[1], dim(df.cluster05)[1], dim(df.cluster06)[1])
barplot(df.clusters.dim,
names.arg = c("cluster01", "cluster02", "cluster03", "cluster04", "cluster05", "cluster06"),
col = "steelblue1")
}
if (!empty_nodes) mpr.hist(df.cluster01)
if (!empty_nodes) mpr.hist(df.cluster02)
if (!empty_nodes) mpr.hist(df.cluster03)
if (!empty_nodes) mpr.hist(df.cluster04)
if (!empty_nodes) mpr.hist(df.cluster05)
if (!empty_nodes) mpr.hist(df.cluster06)
if (!empty_nodes) mpr.boxplot(df.cluster01)
if (!empty_nodes) mpr.boxplot(df.cluster02)
if (!empty_nodes) mpr.boxplot(df.cluster03)
if (!empty_nodes) mpr.boxplot(df.cluster04)
if (!empty_nodes) mpr.boxplot(df.cluster05)
if (!empty_nodes) mpr.boxplot(df.cluster06)
# Agrupa por longitud y latitud para rellenar el mapa con menos datos.
if (!empty_nodes) {
df.cluster01.grouped <- mpr.group_by_geo(df.cluster01)
df.cluster02.grouped <- mpr.group_by_geo(df.cluster02)
df.cluster03.grouped <- mpr.group_by_geo(df.cluster03)
df.cluster04.grouped <- mpr.group_by_geo(df.cluster04)
df.cluster05.grouped <- mpr.group_by_geo(df.cluster05)
df.cluster06.grouped <- mpr.group_by_geo(df.cluster06)
}
if (!empty_nodes) mpr.draw_map(spain, df.cluster01.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster02.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster03.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster04.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster05.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster06.grouped)
if (!empty_nodes) {
plot(hac, hang=-1, labels=F)
rect.hclust(hac, k=8)
}
A quĂ© clĂºster pertenece cada nodo del mapa de kohonen:
if (!empty_nodes) {
groups <- cutree(hac, k=8)
plot(model, type="mapping",
bgcol=c("steelblue1","sienna1","yellowgreen","red","blue","yellow","purple","green","white","#1f77b4", '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#8c564b', '#e377c2')[groups],
shape = "straight", labels = "")
add.cluster.boundaries(model, clustering=groups)
}
if (!empty_nodes) {
# Asignamos a cada registro su clĂºster
df$cluster <- groups[model$unit.classif]
}
Nuevos dataframes por cluster
if (!empty_nodes) {
# Creo nuevos dataframes, uno por cada clĂºster.
df.cluster01 <- subset(df, cluster==1)
df.cluster02 <- subset(df, cluster==2)
df.cluster03 <- subset(df, cluster==3)
df.cluster04 <- subset(df, cluster==4)
df.cluster05 <- subset(df, cluster==5)
df.cluster06 <- subset(df, cluster==6)
df.cluster07 <- subset(df, cluster==7)
df.cluster08 <- subset(df, cluster==8)
# Extraigo del dataframe las features.
df.cluster01 <- select(df.cluster01, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster02 <- select(df.cluster02, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster03 <- select(df.cluster03, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster04 <- select(df.cluster04, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster05 <- select(df.cluster05, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster06 <- select(df.cluster06, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster07 <- select(df.cluster07, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster08 <- select(df.cluster08, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
}
if (!empty_nodes) summary(df.cluster01)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. : 87.0 Min. : 20.00 Min. : 0.00 Min. :0
1st Qu.: 4.000 1st Qu.:185.0 1st Qu.: 85.00 1st Qu.: 6.00 1st Qu.:0
Median : 5.000 Median :199.0 Median : 99.00 Median : 14.00 Median :0
Mean : 6.613 Mean :199.6 Mean : 97.74 Mean : 19.25 Mean :0
3rd Qu.:10.000 3rd Qu.:215.0 3rd Qu.:111.00 3rd Qu.: 26.00 3rd Qu.:0
Max. :12.000 Max. :265.0 Max. :157.00 Max. :279.00 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.00000 Min. :27.82 Min. :-17.8889 Min. : 1.0
1st Qu.: 0.00000 1st Qu.:37.96 1st Qu.: -5.6156 1st Qu.: 32.0
Median : 0.00000 Median :40.66 Median : -2.9553 Median : 98.0
Mean : 0.02868 Mean :39.80 Mean : -3.0701 Mean : 339.7
3rd Qu.: 0.00000 3rd Qu.:42.08 3rd Qu.: 0.4914 3rd Qu.: 570.8
Max. :38.00000 Max. :43.57 Max. : 4.2156 Max. :2519.0
if (!empty_nodes) summary(df.cluster02)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. :109.0 Min. :-31.00 Min. : 0.00 Min. :0
1st Qu.: 2.000 1st Qu.:146.0 1st Qu.: 49.00 1st Qu.: 6.00 1st Qu.:0
Median : 4.000 Median :158.0 Median : 62.00 Median : 16.00 Median :0
Mean : 5.631 Mean :158.3 Mean : 61.56 Mean : 22.21 Mean :0
3rd Qu.:11.000 3rd Qu.:170.0 3rd Qu.: 74.00 3rd Qu.: 30.00 3rd Qu.:0
Max. :12.000 Max. :250.0 Max. :115.00 Max. :371.00 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.00000 Min. :28.31 Min. :-16.4992 Min. : 1.0
1st Qu.: 0.00000 1st Qu.:39.47 1st Qu.: -5.6156 1st Qu.: 44.0
Median : 0.00000 Median :41.22 Median : -2.9056 Median : 185.0
Mean : 0.05081 Mean :40.61 Mean : -2.7805 Mean : 374.7
3rd Qu.: 0.00000 3rd Qu.:42.44 3rd Qu.: 0.5706 3rd Qu.: 611.0
Max. :59.00000 Max. :43.57 Max. : 4.2156 Max. :2535.0
if (!empty_nodes) summary(df.cluster03)
fecha_cnt tmax tmin precip
Min. : 1.000 Min. : 74.0 Min. :-35.0 Min. : 0
1st Qu.: 2.000 1st Qu.:113.0 1st Qu.: 18.0 1st Qu.: 6
Median : 3.000 Median :122.0 Median : 32.0 Median : 14
Mean : 5.645 Mean :122.5 Mean : 29.6 Mean : 21
3rd Qu.:11.000 3rd Qu.:131.0 3rd Qu.: 42.0 3rd Qu.: 28
Max. :12.000 Max. :199.0 Max. : 76.0 Max. :280
nevada prof_nieve longitud latitud
Min. :0.0000000 Min. : 0.0000 Min. :28.31 Min. :-16.4992
1st Qu.:0.0000000 1st Qu.: 0.0000 1st Qu.:40.48 1st Qu.: -4.6992
Median :0.0000000 Median : 0.0000 Median :41.57 Median : -3.1642
Mean :0.0004625 Mean : 0.1183 Mean :41.04 Mean : -2.8891
3rd Qu.:0.0000000 3rd Qu.: 0.0000 3rd Qu.:42.40 3rd Qu.: 0.3264
Max. :2.0000000 Max. :65.0000 Max. :43.57 Max. : 4.2156
altitud
Min. : 1.0
1st Qu.: 263.0
Median : 567.0
Mean : 638.7
3rd Qu.: 790.0
Max. :2535.0
if (!empty_nodes) summary(df.cluster04)
fecha_cnt tmax tmin precip
Min. : 1.000 Min. : 20.00 Min. :-80.00000 Min. : 0.00
1st Qu.: 1.000 1st Qu.: 74.00 1st Qu.:-13.00000 1st Qu.: 5.00
Median : 2.000 Median : 89.00 Median : 2.00000 Median : 12.00
Mean : 5.502 Mean : 86.25 Mean : 0.04525 Mean : 17.78
3rd Qu.:12.000 3rd Qu.:100.00 3rd Qu.: 15.00000 3rd Qu.: 24.00
Max. :12.000 Max. :164.00 Max. : 45.00000 Max. :309.00
nevada prof_nieve longitud latitud
Min. :0.000000 Min. : 0.000 Min. :28.31 Min. :-16.499
1st Qu.:0.000000 1st Qu.: 0.000 1st Qu.:40.70 1st Qu.: -4.680
Median :0.000000 Median : 0.000 Median :41.60 Median : -3.164
Mean :0.002896 Mean : 2.628 Mean :40.86 Mean : -3.009
3rd Qu.:0.000000 3rd Qu.: 0.000 3rd Qu.:42.36 3rd Qu.: -1.008
Max. :6.000000 Max. :1494.000 Max. :43.54 Max. : 3.166
altitud
Min. : 2
1st Qu.: 617
Median : 846
Mean : 978
3rd Qu.:1082
Max. :2535
if (!empty_nodes) summary(df.cluster05)
fecha_cnt tmax tmin precip
Min. : 1.000 Min. :-53.000 Min. :-121.00 Min. : 0.00
1st Qu.: 2.000 1st Qu.: -4.000 1st Qu.: -65.00 1st Qu.: 17.00
Median : 3.000 Median : 11.000 Median : -51.00 Median : 33.00
Mean : 4.798 Mean : 8.683 Mean : -54.46 Mean : 38.67
3rd Qu.:11.000 3rd Qu.: 23.000 3rd Qu.: -41.00 3rd Qu.: 54.00
Max. :12.000 Max. : 75.000 Max. : -20.00 Max. :180.00
nevada prof_nieve longitud latitud
Min. :0 Min. : 0.00 Min. :28.31 Min. :-16.49920
1st Qu.:0 1st Qu.: 0.00 1st Qu.:42.18 1st Qu.: 0.73170
Median :0 Median : 0.00 Median :42.47 Median : 0.98440
Mean :0 Mean : 26.19 Mean :42.12 Mean : 0.01983
3rd Qu.:0 3rd Qu.: 0.00 3rd Qu.:42.64 3rd Qu.: 1.36560
Max. :0 Max. :1834.00 Max. :42.85 Max. : 2.43780
altitud
Min. : 162
1st Qu.:1894
Median :2247
Mean :2165
3rd Qu.:2400
Max. :2535
if (!empty_nodes) summary(df.cluster06)
fecha_cnt tmax tmin precip nevada
Min. : 1.00 Min. :173.0 Min. : 57 Min. : 0.00 Min. :0
1st Qu.: 6.00 1st Qu.:226.0 1st Qu.:127 1st Qu.: 3.00 1st Qu.:0
Median : 7.00 Median :246.0 Median :141 Median : 9.00 Median :0
Mean : 7.18 Mean :246.3 Mean :140 Mean : 13.15 Mean :0
3rd Qu.: 9.00 3rd Qu.:267.0 3rd Qu.:156 3rd Qu.: 18.00 3rd Qu.:0
Max. :12.00 Max. :336.0 Max. :195 Max. :422.00 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.00000 Min. :27.82 Min. :-17.8889 Min. : 1
1st Qu.: 0.00000 1st Qu.:37.26 1st Qu.: -6.2567 1st Qu.: 32
Median : 0.00000 Median :40.82 Median : -3.7892 Median : 98
Mean : 0.00444 Mean :38.93 Mean : -4.5345 Mean : 318
3rd Qu.: 0.00000 3rd Qu.:42.18 3rd Qu.: 0.0406 3rd Qu.: 609
Max. :35.00000 Max. :43.57 Max. : 4.2156 Max. :2371
if (!empty_nodes) summary(df.cluster07)
fecha_cnt tmax tmin precip nevada
Min. : 2.000 Min. :226.0 Min. :173.0 Min. : 0.000 Min. :0
1st Qu.: 7.000 1st Qu.:262.0 1st Qu.:191.0 1st Qu.: 0.000 1st Qu.:0
Median : 8.000 Median :276.0 Median :203.0 Median : 1.000 Median :0
Mean : 7.796 Mean :277.6 Mean :202.7 Mean : 5.093 Mean :0
3rd Qu.: 9.000 3rd Qu.:292.0 3rd Qu.:213.0 3rd Qu.: 5.000 3rd Qu.:0
Max. :12.000 Max. :340.0 Max. :254.0 Max. :218.000 Max. :0
prof_nieve longitud latitud altitud
Min. :0.0000000 Min. :27.82 Min. :-17.8889 Min. : 1.00
1st Qu.:0.0000000 1st Qu.:28.63 1st Qu.:-13.8631 1st Qu.: 7.00
Median :0.0000000 Median :36.85 Median : -2.4544 Median : 25.00
Mean :0.0002894 Mean :35.51 Mean : -5.2987 Mean : 48.29
3rd Qu.:0.0000000 3rd Qu.:39.49 3rd Qu.: 0.7106 3rd Qu.: 44.00
Max. :2.0000000 Max. :43.56 Max. : 4.2156 Max. :1004.00
if (!empty_nodes) summary(df.cluster08)
fecha_cnt tmax tmin precip nevada
Min. : 5.000 Min. :280.0 Min. :111.0 Min. : 0.000 Min. :0
1st Qu.: 7.000 1st Qu.:303.0 1st Qu.:161.0 1st Qu.: 0.000 1st Qu.:0
Median : 7.000 Median :317.0 Median :175.0 Median : 2.000 Median :0
Mean : 7.442 Mean :319.2 Mean :174.7 Mean : 4.995 Mean :0
3rd Qu.: 8.000 3rd Qu.:333.0 3rd Qu.:188.0 3rd Qu.: 7.000 3rd Qu.:0
Max. :12.000 Max. :403.0 Max. :250.0 Max. :320.000 Max. :0
prof_nieve longitud latitud altitud
Min. :0 Min. :28.44 Min. :-17.7550 Min. : 1.0
1st Qu.:0 1st Qu.:37.84 1st Qu.: -4.8458 1st Qu.: 71.0
Median :0 Median :39.88 Median : -3.4503 Median : 247.0
Mean :0 Mean :39.64 Mean : -2.5883 Mean : 339.9
3rd Qu.:0 3rd Qu.:41.31 3rd Qu.: 0.4731 3rd Qu.: 611.0
Max. :0 Max. :43.30 Max. : 4.2156 Max. :1167.0
if (!empty_nodes) {
df.clusters.dim <- c(dim(df.cluster01)[1], dim(df.cluster02)[1], dim(df.cluster03)[1], dim(df.cluster04)[1], dim(df.cluster05)[1], dim(df.cluster06)[1], dim(df.cluster07)[1], dim(df.cluster08)[1])
barplot(df.clusters.dim,
names.arg = c("cluster01", "cluster02", "cluster03", "cluster04", "cluster05", "cluster06", "cluster07", "cluster08"),
col = "steelblue1")
}
if (!empty_nodes) mpr.hist(df.cluster01)
if (!empty_nodes) mpr.hist(df.cluster02)
if (!empty_nodes) mpr.hist(df.cluster03)
if (!empty_nodes) mpr.hist(df.cluster04)
if (!empty_nodes) mpr.hist(df.cluster05)
if (!empty_nodes) mpr.hist(df.cluster06)
if (!empty_nodes) mpr.hist(df.cluster07)
if (!empty_nodes) mpr.hist(df.cluster08)
if (!empty_nodes) mpr.boxplot(df.cluster01)
if (!empty_nodes) mpr.boxplot(df.cluster02)
if (!empty_nodes) mpr.boxplot(df.cluster03)
if (!empty_nodes) mpr.boxplot(df.cluster04)
if (!empty_nodes) mpr.boxplot(df.cluster05)
if (!empty_nodes) mpr.boxplot(df.cluster06)
if (!empty_nodes) mpr.boxplot(df.cluster07)
if (!empty_nodes) mpr.boxplot(df.cluster08)
# Agrupa por longitud y latitud para rellenar el mapa con menos datos.
if (!empty_nodes) {
df.cluster01.grouped <- mpr.group_by_geo(df.cluster01)
df.cluster02.grouped <- mpr.group_by_geo(df.cluster02)
df.cluster03.grouped <- mpr.group_by_geo(df.cluster03)
df.cluster04.grouped <- mpr.group_by_geo(df.cluster04)
df.cluster05.grouped <- mpr.group_by_geo(df.cluster05)
df.cluster06.grouped <- mpr.group_by_geo(df.cluster06)
df.cluster07.grouped <- mpr.group_by_geo(df.cluster07)
df.cluster08.grouped <- mpr.group_by_geo(df.cluster08)
}
if (!empty_nodes) mpr.draw_map(spain, df.cluster01.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster02.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster03.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster04.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster05.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster06.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster07.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster08.grouped)
if (!empty_nodes) {
plot(hac, hang=-1, labels=F)
rect.hclust(hac, k=10)
}
A quĂ© clĂºster pertenece cada nodo del mapa de kohonen:
if (!empty_nodes) {
groups <- cutree(hac, k=10)
plot(model, type="mapping",
bgcol=c("steelblue1","sienna1","yellowgreen","red","blue","yellow","purple","green","white","#1f77b4", '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#8c564b', '#e377c2')[groups],
shape = "straight", labels = "")
add.cluster.boundaries(model, clustering=groups)
}
if (!empty_nodes) {
# Asignamos a cada registro su clĂºster
df$cluster <- groups[model$unit.classif]
}
Nuevos dataframes por cluster
if (!empty_nodes) {
# Creo nuevos dataframes, uno por cada clĂºster.
df.cluster01 <- subset(df, cluster==1)
df.cluster02 <- subset(df, cluster==2)
df.cluster03 <- subset(df, cluster==3)
df.cluster04 <- subset(df, cluster==4)
df.cluster05 <- subset(df, cluster==5)
df.cluster06 <- subset(df, cluster==6)
df.cluster07 <- subset(df, cluster==7)
df.cluster08 <- subset(df, cluster==8)
df.cluster09 <- subset(df, cluster==9)
df.cluster10 <- subset(df, cluster==10)
# Extraigo del dataframe las features.
df.cluster01 <- select(df.cluster01, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster02 <- select(df.cluster02, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster03 <- select(df.cluster03, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster04 <- select(df.cluster04, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster05 <- select(df.cluster05, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster06 <- select(df.cluster06, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster07 <- select(df.cluster07, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster08 <- select(df.cluster08, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster09 <- select(df.cluster09, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster10 <- select(df.cluster10, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
}
if (!empty_nodes) summary(df.cluster01)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. : 87.0 Min. : 20.00 Min. : 0.00 Min. :0
1st Qu.: 4.000 1st Qu.:185.0 1st Qu.: 85.00 1st Qu.: 6.00 1st Qu.:0
Median : 5.000 Median :199.0 Median : 99.00 Median : 14.00 Median :0
Mean : 6.613 Mean :199.6 Mean : 97.74 Mean : 19.25 Mean :0
3rd Qu.:10.000 3rd Qu.:215.0 3rd Qu.:111.00 3rd Qu.: 26.00 3rd Qu.:0
Max. :12.000 Max. :265.0 Max. :157.00 Max. :279.00 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.00000 Min. :27.82 Min. :-17.8889 Min. : 1.0
1st Qu.: 0.00000 1st Qu.:37.96 1st Qu.: -5.6156 1st Qu.: 32.0
Median : 0.00000 Median :40.66 Median : -2.9553 Median : 98.0
Mean : 0.02868 Mean :39.80 Mean : -3.0701 Mean : 339.7
3rd Qu.: 0.00000 3rd Qu.:42.08 3rd Qu.: 0.4914 3rd Qu.: 570.8
Max. :38.00000 Max. :43.57 Max. : 4.2156 Max. :2519.0
if (!empty_nodes) summary(df.cluster02)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. :109.0 Min. :-31.00 Min. : 0.00 Min. :0
1st Qu.: 2.000 1st Qu.:146.0 1st Qu.: 49.00 1st Qu.: 6.00 1st Qu.:0
Median : 4.000 Median :158.0 Median : 62.00 Median : 16.00 Median :0
Mean : 5.631 Mean :158.3 Mean : 61.56 Mean : 22.21 Mean :0
3rd Qu.:11.000 3rd Qu.:170.0 3rd Qu.: 74.00 3rd Qu.: 30.00 3rd Qu.:0
Max. :12.000 Max. :250.0 Max. :115.00 Max. :371.00 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.00000 Min. :28.31 Min. :-16.4992 Min. : 1.0
1st Qu.: 0.00000 1st Qu.:39.47 1st Qu.: -5.6156 1st Qu.: 44.0
Median : 0.00000 Median :41.22 Median : -2.9056 Median : 185.0
Mean : 0.05081 Mean :40.61 Mean : -2.7805 Mean : 374.7
3rd Qu.: 0.00000 3rd Qu.:42.44 3rd Qu.: 0.5706 3rd Qu.: 611.0
Max. :59.00000 Max. :43.57 Max. : 4.2156 Max. :2535.0
if (!empty_nodes) summary(df.cluster03)
fecha_cnt tmax tmin precip
Min. : 1.000 Min. : 74.0 Min. :-35.0 Min. : 0
1st Qu.: 2.000 1st Qu.:113.0 1st Qu.: 18.0 1st Qu.: 6
Median : 3.000 Median :122.0 Median : 32.0 Median : 14
Mean : 5.645 Mean :122.5 Mean : 29.6 Mean : 21
3rd Qu.:11.000 3rd Qu.:131.0 3rd Qu.: 42.0 3rd Qu.: 28
Max. :12.000 Max. :199.0 Max. : 76.0 Max. :280
nevada prof_nieve longitud latitud
Min. :0.0000000 Min. : 0.0000 Min. :28.31 Min. :-16.4992
1st Qu.:0.0000000 1st Qu.: 0.0000 1st Qu.:40.48 1st Qu.: -4.6992
Median :0.0000000 Median : 0.0000 Median :41.57 Median : -3.1642
Mean :0.0004625 Mean : 0.1183 Mean :41.04 Mean : -2.8891
3rd Qu.:0.0000000 3rd Qu.: 0.0000 3rd Qu.:42.40 3rd Qu.: 0.3264
Max. :2.0000000 Max. :65.0000 Max. :43.57 Max. : 4.2156
altitud
Min. : 1.0
1st Qu.: 263.0
Median : 567.0
Mean : 638.7
3rd Qu.: 790.0
Max. :2535.0
if (!empty_nodes) summary(df.cluster04)
fecha_cnt tmax tmin precip
Min. : 1.000 Min. : 20.00 Min. :-80.00000 Min. : 0.00
1st Qu.: 1.000 1st Qu.: 74.00 1st Qu.:-13.00000 1st Qu.: 5.00
Median : 2.000 Median : 89.00 Median : 2.00000 Median : 12.00
Mean : 5.502 Mean : 86.25 Mean : 0.04525 Mean : 17.78
3rd Qu.:12.000 3rd Qu.:100.00 3rd Qu.: 15.00000 3rd Qu.: 24.00
Max. :12.000 Max. :164.00 Max. : 45.00000 Max. :309.00
nevada prof_nieve longitud latitud
Min. :0.000000 Min. : 0.000 Min. :28.31 Min. :-16.499
1st Qu.:0.000000 1st Qu.: 0.000 1st Qu.:40.70 1st Qu.: -4.680
Median :0.000000 Median : 0.000 Median :41.60 Median : -3.164
Mean :0.002896 Mean : 2.628 Mean :40.86 Mean : -3.009
3rd Qu.:0.000000 3rd Qu.: 0.000 3rd Qu.:42.36 3rd Qu.: -1.008
Max. :6.000000 Max. :1494.000 Max. :43.54 Max. : 3.166
altitud
Min. : 2
1st Qu.: 617
Median : 846
Mean : 978
3rd Qu.:1082
Max. :2535
if (!empty_nodes) summary(df.cluster05)
fecha_cnt tmax tmin precip
Min. : 1.000 Min. :-53.000 Min. :-121.00 Min. : 0.00
1st Qu.: 2.000 1st Qu.: -4.000 1st Qu.: -65.00 1st Qu.: 17.00
Median : 3.000 Median : 11.000 Median : -51.00 Median : 33.00
Mean : 4.798 Mean : 8.683 Mean : -54.46 Mean : 38.67
3rd Qu.:11.000 3rd Qu.: 23.000 3rd Qu.: -41.00 3rd Qu.: 54.00
Max. :12.000 Max. : 75.000 Max. : -20.00 Max. :180.00
nevada prof_nieve longitud latitud
Min. :0 Min. : 0.00 Min. :28.31 Min. :-16.49920
1st Qu.:0 1st Qu.: 0.00 1st Qu.:42.18 1st Qu.: 0.73170
Median :0 Median : 0.00 Median :42.47 Median : 0.98440
Mean :0 Mean : 26.19 Mean :42.12 Mean : 0.01983
3rd Qu.:0 3rd Qu.: 0.00 3rd Qu.:42.64 3rd Qu.: 1.36560
Max. :0 Max. :1834.00 Max. :42.85 Max. : 2.43780
altitud
Min. : 162
1st Qu.:1894
Median :2247
Mean :2165
3rd Qu.:2400
Max. :2535
if (!empty_nodes) summary(df.cluster06)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. :173 Min. :123.0 Min. : 0.00 Min. :0
1st Qu.: 5.000 1st Qu.:209 1st Qu.:141.0 1st Qu.: 2.00 1st Qu.:0
Median : 7.000 Median :221 Median :153.0 Median : 10.00 Median :0
Mean : 6.967 Mean :221 Mean :152.7 Mean : 15.65 Mean :0
3rd Qu.:10.000 3rd Qu.:233 3rd Qu.:164.0 3rd Qu.: 22.00 3rd Qu.:0
Max. :12.000 Max. :255 Max. :195.0 Max. :422.00 Max. :0
prof_nieve longitud latitud altitud
Min. :0.000000 Min. :27.82 Min. :-17.889 Min. : 1
1st Qu.:0.000000 1st Qu.:28.48 1st Qu.:-15.389 1st Qu.: 21
Median :0.000000 Median :37.78 Median : -5.642 Median : 35
Mean :0.001196 Mean :36.52 Mean : -7.333 Mean : 133
3rd Qu.:0.000000 3rd Qu.:43.31 3rd Qu.: -2.039 3rd Qu.: 87
Max. :3.000000 Max. :43.57 Max. : 4.216 Max. :2371
if (!empty_nodes) summary(df.cluster07)
fecha_cnt tmax tmin precip nevada
Min. : 2.000 Min. :226.0 Min. :173.0 Min. : 0.000 Min. :0
1st Qu.: 7.000 1st Qu.:262.0 1st Qu.:191.0 1st Qu.: 0.000 1st Qu.:0
Median : 8.000 Median :276.0 Median :203.0 Median : 1.000 Median :0
Mean : 7.796 Mean :277.6 Mean :202.7 Mean : 5.093 Mean :0
3rd Qu.: 9.000 3rd Qu.:292.0 3rd Qu.:213.0 3rd Qu.: 5.000 3rd Qu.:0
Max. :12.000 Max. :340.0 Max. :254.0 Max. :218.000 Max. :0
prof_nieve longitud latitud altitud
Min. :0.0000000 Min. :27.82 Min. :-17.8889 Min. : 1.00
1st Qu.:0.0000000 1st Qu.:28.63 1st Qu.:-13.8631 1st Qu.: 7.00
Median :0.0000000 Median :36.85 Median : -2.4544 Median : 25.00
Mean :0.0002894 Mean :35.51 Mean : -5.2987 Mean : 48.29
3rd Qu.:0.0000000 3rd Qu.:39.49 3rd Qu.: 0.7106 3rd Qu.: 44.00
Max. :2.0000000 Max. :43.56 Max. : 4.2156 Max. :1004.00
if (!empty_nodes) summary(df.cluster08)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. :226.0 Min. : 57.0 Min. : 0.00 Min. :0
1st Qu.: 5.000 1st Qu.:240.0 1st Qu.:108.0 1st Qu.: 4.00 1st Qu.:0
Median : 7.000 Median :248.0 Median :123.0 Median : 10.00 Median :0
Mean : 7.222 Mean :248.5 Mean :120.4 Mean : 13.05 Mean :0
3rd Qu.: 9.000 3rd Qu.:256.0 3rd Qu.:134.0 3rd Qu.: 18.00 3rd Qu.:0
Max. :12.000 Max. :296.0 Max. :151.0 Max. :190.00 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.00000 Min. :27.92 Min. :-16.5606 Min. : 1.0
1st Qu.: 0.00000 1st Qu.:39.48 1st Qu.: -5.6000 1st Qu.: 81.0
Median : 0.00000 Median :41.11 Median : -2.9056 Median : 415.0
Mean : 0.01309 Mean :40.57 Mean : -2.8921 Mean : 446.1
3rd Qu.: 0.00000 3rd Qu.:42.24 3rd Qu.: 0.3264 3rd Qu.: 704.0
Max. :35.00000 Max. :43.57 Max. : 4.2156 Max. :2371.0
if (!empty_nodes) summary(df.cluster09)
fecha_cnt tmax tmin precip nevada
Min. : 5.000 Min. :280.0 Min. :111.0 Min. : 0.000 Min. :0
1st Qu.: 7.000 1st Qu.:303.0 1st Qu.:161.0 1st Qu.: 0.000 1st Qu.:0
Median : 7.000 Median :317.0 Median :175.0 Median : 2.000 Median :0
Mean : 7.442 Mean :319.2 Mean :174.7 Mean : 4.995 Mean :0
3rd Qu.: 8.000 3rd Qu.:333.0 3rd Qu.:188.0 3rd Qu.: 7.000 3rd Qu.:0
Max. :12.000 Max. :403.0 Max. :250.0 Max. :320.000 Max. :0
prof_nieve longitud latitud altitud
Min. :0 Min. :28.44 Min. :-17.7550 Min. : 1.0
1st Qu.:0 1st Qu.:37.84 1st Qu.: -4.8458 1st Qu.: 71.0
Median :0 Median :39.88 Median : -3.4503 Median : 247.0
Mean :0 Mean :39.64 Mean : -2.5883 Mean : 339.9
3rd Qu.:0 3rd Qu.:41.31 3rd Qu.: 0.4731 3rd Qu.: 611.0
Max. :0 Max. :43.30 Max. : 4.2156 Max. :1167.0
if (!empty_nodes) summary(df.cluster10)
fecha_cnt tmax tmin precip nevada
Min. : 3.000 Min. :251.0 Min. : 91.0 Min. : 0.000 Min. :0
1st Qu.: 6.000 1st Qu.:269.0 1st Qu.:129.0 1st Qu.: 2.000 1st Qu.:0
Median : 7.000 Median :277.0 Median :144.0 Median : 7.000 Median :0
Mean : 7.417 Mean :277.6 Mean :142.9 Mean : 9.946 Mean :0
3rd Qu.: 9.000 3rd Qu.:286.0 3rd Qu.:157.0 3rd Qu.: 14.000 3rd Qu.:0
Max. :12.000 Max. :336.0 Max. :177.0 Max. :132.000 Max. :0
prof_nieve longitud latitud altitud
Min. :0 Min. :27.92 Min. :-16.5606 Min. : 1.0
1st Qu.:0 1st Qu.:39.47 1st Qu.: -4.8500 1st Qu.: 81.0
Median :0 Median :40.96 Median : -2.4831 Median : 442.0
Mean :0 Mean :40.44 Mean : -2.4996 Mean : 432.9
3rd Qu.:0 3rd Qu.:41.84 3rd Qu.: 0.4914 3rd Qu.: 704.0
Max. :0 Max. :43.43 Max. : 4.2156 Max. :2371.0
if (!empty_nodes) {
df.clusters.dim <- c(dim(df.cluster01)[1], dim(df.cluster02)[1], dim(df.cluster03)[1], dim(df.cluster04)[1], dim(df.cluster05)[1], dim(df.cluster06)[1], dim(df.cluster07)[1], dim(df.cluster08)[1], dim(df.cluster09)[1], dim(df.cluster10)[1])
barplot(df.clusters.dim,
names.arg = c("cluster01", "cluster02", "cluster03", "cluster04", "cluster05", "cluster06", "cluster07", "cluster08", "cluster09", "cluster10"),
col = "steelblue1")
}
if (!empty_nodes) mpr.hist(df.cluster01)
if (!empty_nodes) mpr.hist(df.cluster02)
if (!empty_nodes) mpr.hist(df.cluster03)
if (!empty_nodes) mpr.hist(df.cluster04)
if (!empty_nodes) mpr.hist(df.cluster05)
if (!empty_nodes) mpr.hist(df.cluster06)
if (!empty_nodes) mpr.hist(df.cluster07)
if (!empty_nodes) mpr.hist(df.cluster08)
if (!empty_nodes) mpr.hist(df.cluster09)
if (!empty_nodes) mpr.hist(df.cluster10)
if (!empty_nodes) mpr.boxplot(df.cluster01)
if (!empty_nodes) mpr.boxplot(df.cluster02)
if (!empty_nodes) mpr.boxplot(df.cluster03)
if (!empty_nodes) mpr.boxplot(df.cluster04)
if (!empty_nodes) mpr.boxplot(df.cluster05)
if (!empty_nodes) mpr.boxplot(df.cluster06)
if (!empty_nodes) mpr.boxplot(df.cluster07)
if (!empty_nodes) mpr.boxplot(df.cluster08)
if (!empty_nodes) mpr.boxplot(df.cluster09)
if (!empty_nodes) mpr.boxplot(df.cluster10)
# Agrupa por longitud y latitud para rellenar el mapa con menos datos.
if (!empty_nodes) {
df.cluster01.grouped <- mpr.group_by_geo(df.cluster01)
df.cluster02.grouped <- mpr.group_by_geo(df.cluster02)
df.cluster03.grouped <- mpr.group_by_geo(df.cluster03)
df.cluster04.grouped <- mpr.group_by_geo(df.cluster04)
df.cluster05.grouped <- mpr.group_by_geo(df.cluster05)
df.cluster06.grouped <- mpr.group_by_geo(df.cluster06)
df.cluster07.grouped <- mpr.group_by_geo(df.cluster07)
df.cluster08.grouped <- mpr.group_by_geo(df.cluster08)
df.cluster09.grouped <- mpr.group_by_geo(df.cluster09)
df.cluster10.grouped <- mpr.group_by_geo(df.cluster10)
}
if (!empty_nodes) mpr.draw_map(spain, df.cluster01.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster02.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster03.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster04.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster05.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster06.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster07.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster08.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster09.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster10.grouped)